<?php
require_once "Authenticator.php";
define('JSON', 0); 
define('XML', 1);
/**
 * Request class, store request data.
 * @static
 * @package meta
 * @author alcaitiff
 */
class Request
{
	private $player,$userID,$responseType,$time,$key,$commands,$debug;
	/**
     *
     * @param string $id
     * @param int $time
     * @param string $key
     * @param int $responseType
     * @param array|string $commands
     * @param boolean $debug
     */
	public function __construct ($id=null,$time=null,$key=null,$responseType=JSON,$commands=array(),$debug=false){
		$this->userID=$id;
		$this->time=$time;
		$this->key=$key;
		$this->debug=$debug;
		$this->responseType=$responseType;
		$this->commands=(is_array($commands))?$commands:explode(';',$commands);
        foreach($this->commands as $index=>$command){
            $this->commands[$index]=htmlentities($command, ENT_NOQUOTES, "UTF-8");
        }
		MessageSystem::setDebug($debug);	
		MessageSystem::addDebugMessage('New request { id:'.$id.
													',time:'.$time.
													',key:'.$key.
													',responseType:'.$responseType.
													',debug:'.$debug.
													',commands:{'.implode(',',$this->commands).'}}');
		$auth= new Authenticator();
		$this->player=$auth->authenticate($id,$time,$key);
	}
	/**
     * Magic get
     * @param string $property
     * @return mixed
     */
	public function __get($property){
		return $this->$property;
	}
}